package code.coolbaby.basal.service;

import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import code.coolbaby.basal.dao.ResourceDao;
import code.coolbaby.basal.entity.Resource;
import code.coolbaby.core.security.ResourceDetailService;

/**
 * 从数据库查询URL--授权定义的ResourceDetailService实现类.
 * 
 * @author Kanine
 */
@Transactional(readOnly = true)
public class ResourceDetailServiceImpl implements ResourceDetailService {

	@Autowired
	private ResourceDao resourceDao;

	public LinkedHashMap<String, String> getRequestMap() throws Exception {
		List<Resource> resourceList = resourceDao.getUrlResourceWithAuthorities();
		LinkedHashMap<String, String> requestMap = new LinkedHashMap<String, String>();
		for (Resource resource : resourceList) {
			requestMap.put(resource.getValue(), resource.getAuthNames());
		}
		return requestMap;
	}

}
